{include 'header.tpl'}
<body>
<div class="contant">
    <div class="header">
        <div class="header_s">
            <span class="back"><a target="_blank" href="adress_manage.html"><i class="iconfont fan">&#xe679;</i></a></span>
            <span class="title">新增收货地址</span>
            <span class="add_ads" id="baocun">保存</span>
            <div class="clear"></div>
        </div>
    </div>


    <div class="adress_cont">
        <ul>
            <li>
                <span>我的姓名</span>
                <input name="textfield" type="text"  id="nickname" class="aderess_name" tabindex="1" placeholder="请输入姓名" >
            </li>
            <li><span>我的手机</span>
                <input name="textfield" type="text"  id="telphone" class="aderess_name" tabindex="1" placeholder="请输入手机号">
            </li>
            <li><span>我的性别</span>
                <select class="adress_nas" title="1" name="sex">
                    <option selected>男</option>
                    <option>女</option>
                </select>
            </li>
        </ul>
    </div>
    <div class="adress_cont">
        <ul>
            <li>
                <span>我的省份</span>
                <select class="adress_nas" title="1" name="city">
                    {foreach from=$cityList item=item name=foo}
                    <option value="{$item.cityId}">{$item.city}</option>
                    {/foreach}
                </select>
            </li>
            <li>
                <span>我的地区</span>
                <select class="adress_nas" title="1" name="county">
                    {foreach from=$county item=item name=foo}
                    <option value="{$item.countyId}">{$item.county}</option>
                    {/foreach}
                </select>
            </li>
            <li>
                <span>详细地址</span>

                <input  id='detail_address' class="aderess_name2" tabindex="1" placeholder="详细到楼栋和门号">
            </li>
        </ul>
    </div>
</div>
<script>
    $('#baocun').click(function (e) {
        var nick = $('#nickname').val();
        var mobile=$('#telphone').val();
        var detail=$('#detail_address').val();
        var sex = $("select[name='sex']").val();
        var city= $("select[name='city']").val();
        var county= $("select[name='county']").val();

        if(nick.length == 0  ){
            alert("称呼不能为空");
            return false;
        }
        //手机号码验证
        if(mobile.length == 0  ){
            alert("注册手机号不能为空");
            return false;
        }
        if(detail.length == 0  ){
            alert("详细地址不能为空");
            return false;
        }

        if(mobile.length!=11)
        {
            alert('请输入有效的手机号码！');
            return false;
        }
        if(!(/^1[34578]\d\d\d\d\d\d\d\d\d$/.test(mobile))){
            alert("手机号码有误，请重填");
            return false;
        }


        $.ajax({
            url: '/add/getaddress',
            type: 'post',
            data:{
                contact:nick,
                phone:mobile,
                address:detail,
                sex:sex,
                city:city,
                county:county
            },
            dataType: "json",

            success:function (data) {
                if(data.status == 200){
                    location.href="/add/addlist"
                }else {
                    alert(data.error);
                }

            },
            error:function (data) {
                alert('服务器异常，请稍候再试！');
            }
        })
    });



</script>
</body>
</html>
